var myOpenId = '' ;
var fun={
    init:function () {
        fun.querySubscribeFun(10,'tab2Content1');
    },
    querySubscribeFun:function (subscribeState,tabId) {
        //获取到的code
         var code = getUrlParam("code");
        //获取openId
        if(myOpenId ==''){
            myOpenId= commonObj.getOpenId(code);
        }
        var openId = myOpenId;
        //var openId = 'oLJDZ5tT-VyXQV5yAjIJOasDJQDw';
        var req={
            baseRequest:{
                pageNum:0,
                pageSize:3000
            },
            openId:openId,
            subscribeState:subscribeState
        };
        var opts = {
            method:'post',
            url: dataUrl.util.querySubscribeInfos(),
            data: JSON.stringify(req),
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function(res) {
                var orders = "";
                if (res.code != '8888') {
                    new $.zui.Messager(res.msg, {
                        type:'danger',
                        time:'3000',
                        icon: 'heart',
                        placement: 'bottom' // 定义显示位置
                    }).show();
                    return false;
                }

                if(res.data==null){
                    //没有订单
                    orders = '暂无订单';
                    $('#mysubscribes').html(orders);
                    return;
                }

                var pageBean = res.data;
                if(pageBean.dataList==null || pageBean.dataList.length<=0){
                    //没有更多了
                    orders = '暂无订单，先去预约吧';
                    $('#mysubscribes').html(orders);
                    return;
                }
                $('#dbnum').val(pageBean.pageTotals);
                // var tabContent = "";
                var i=0;
                $.each(pageBean.dataList,function(index,order){
                    //出发地，目的的
                    var cityStr = order.fromCityName +'-'+order.toCityName;

                    var content = order.subscribePeopNum+'人'+((order.subscribeType==1)?'拼车':'包车')+','+((order.carType==1)?'小轿车':'商务车'+';');
                    //content += "司机:"+order.driverPhoneNo+',车牌:'+order.carNum;
                    orders +='<div class="panel panel-default">' +
                        '                <div class="panel-heading " id="headingOne'+i+'">' +
                        '                    <h4 class="panel-title">' +
                        '                        <a data-toggle="collapse" class="taxi-cursor" data-parent="#accordionPanels" href="#collapseOne'+tabId+i+'">' +
                        '                            <div class="pos_rel">' +
                        '                                <div class="float-left bj_timesta" >'+DateUtils.long2String(order.subscribeTime,1)+'</div>' +
                        '                                <div class="float-left bj_cityName taxi-hidden-nowrap" title="'+cityStr+'">'+cityStr+'</div>' +
                        // '                                <div class="float-left bj_type" >'+stateStr+'</div>' +
                        '                                <div class="pos_abs bj_sort"><i class="icon icon-sort"></i></div>' +
                        '                            </div>' +
                        '                        </a>' +
                        '                    </h4>' +
                        '                </div>' +
                        '                <div id="collapseOne'+tabId+i+'" class="panel-collapse collapse">' +
                        '                    <div class="panel-body">' +
                        '                        <p>备注:'+content+'</p>'+
                        '                    </div>' +
                        '                </div>' +
                        '            </div>';
                    i++;

                });
                //添加到界面
                $('#'+tabId).html(orders);
            }
        };
        sysAjax(opts);
    }
}
fun.init();

$('[data-tab]').on('show.zui.tab', function(e) {
    if(e.target.dataset.target=='#tab2Content1'){
        //待接单
        fun.querySubscribeFun(10,'tab2Content1');
    }else if(e.target.dataset.target=='#tab2Content2'){
        //已接单
        fun.querySubscribeFun(20,'tab2Content2');
    }else if(e.target.dataset.target=='#tab2Content3'){
        //已失败
        fun.querySubscribeFun(-10,'tab2Content3');
    }
});

